package com.sexymobileframework.uicomponent;

import java.lang.reflect.Field;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class UIComponentFactory 
{
	public UIComponentFactory()
	{
		
	}
	
	public static int getUIComponentType(Node UIComponentNode)
	{
		try
		{
			String prefix = new String("UICOMPONENT_TYPE_");
			
			String UIComponentType = prefix + UIComponentNode.getNodeName().toUpperCase();
			
			Field type = UIComponent.class.getDeclaredField(UIComponentType);
			
			return type.getInt(UIComponent.class);
			
		}
		catch (NoSuchFieldException e) 
		{
			e.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return UIComponent.UICOMPONENT_TYPE_NULL;
	}
	
	
	public static UIComponent createUIComponent(Node currUIComponentNode)
	{
		UIComponent newUIComponent = null;
		
		int UIComponentType = getUIComponentType(currUIComponentNode);
		
		switch(UIComponentType)
		{
			case UIComponent.UICOMPONENT_TYPE_MENU:
				newUIComponent = new Menu(currUIComponentNode);
				break;
			case UIComponent.UICOMPONENT_TYPE_MENUITEM:
				newUIComponent = new Menu(currUIComponentNode);
				break;
			default:
				newUIComponent = null;
		}
		
		
		return newUIComponent; 
	}
}
